package com.briup.day05;

import java.util.Arrays;

public class Test_Case {
    public static void main(String[] args) {
        int[] arr=new int[]{1,3,4,6,8};
        double sum=getAverage(arr);
        System.out.println(sum);
        int[] arr1=new int[]{1,2,3,4,5};
        int sec=getSec(arr1);
        System.out.println(sec);
        reverse(arr1);
        System.out.println(Arrays.toString(arr1));
    }
    public static double getAverage(int[] arr){
        int sum=0;
        for(int  i=0;i<arr.length;i++){
            sum+=arr[i];
        }
        return sum/arr.length;
    }
    //求次大值
    /*
    *
    * */
    public static void reverse(int[] arr){
        for(int i=0;i<arr.length/2;i++){
            arr[i]=arr[arr.length-i-1]^arr[i];
            arr[arr.length-i-1]=arr[i]^arr[arr.length-i-1];
            arr[i]=arr[arr.length-i-1]^arr[i];
        }
    }
    public static int getSec(int[] arr){
        int max=arr[0];
        int sec=arr[1];
        max=arr[0]>arr[1]?arr[0]:arr[1];
        sec=arr[0]<arr[1]?arr[0]:arr[1];
        for(int j=2;j<arr.length;j++){
            if(arr[j]>max){
                sec=max;
                max=arr[j];
            }else if(arr[j]<max&&arr[j]>sec){
                sec=arr[j];
            }
        }
        return sec;
    }
}
